﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;
using System.Data;
using System.Text;

namespace ZLDC.Estate.Quantify
{
    public partial class lp_Nissin_Bi : _PageBase
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
              //查询经理今天分配的工作"
              DataSet ds=null;
              string sSql = "select b.id,b.BasisName,c.Point,c.Highest,c.Quantity,b.SystemSouce,c.unit from lp_Configuration_main as a right join  lp_Configuration as b on a.ID=b.mainId inner join  lp_Basis as c on b.BasisName=c.Name where a.userID="+_Utility.GetInfoBySession().m_sUserID+" and DATEDIFF(DD,a.workDay,GETDATE())=0 and a.isComplete=0 ";
                 using(_Database db=new _Database("estate"))
                 {
                    ds=db.Query(sSql);
                 }

                 if (ds.Tables[0].Rows.Count > 0)//判断今天经理是否分配工作
                 {
                     //绑定量化项目，经理分配的工作项
                         grView2.DataSource = ds;
                         grView2.DataBind();
                 }

                
            
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            int total = 0;
            StringBuilder sb = new StringBuilder();

            foreach(GridViewRow gr in grView2.Rows)
            {
                Label lblId = (Label)FindControl("lblId");//ID
                TextBox txtCount = (TextBox)FindControl("txtCount");//实际完成数量
                Label lblpoint = (Label)FindControl("lblpoint");//分值
                Label lblquantity = (Label)FindControl("lblquantity");//数量
                Label lblHighest = (Label)FindControl("lblHighest");//最高分

                int SumScors = _Convert.ToInt(lblpoint.Text) / _Convert.ToInt(lblquantity.Text) * _Convert.ToInt(txtCount.Text); //单项总分
                if (SumScors >= _Convert.ToInt(lblHighest.Text, 0))
                {
                    SumScors = _Convert.ToInt(lblHighest.Text);
                }

                total = total + SumScors;//各项总分

                sb.Append("update lp_Configuration set Quantity="+txtCount.Text+",SystemSouce="+SumScors+",Complete=1,UpdateUser="+_Utility.GetInfoBySession().m_sUserName+",UpdateTime=GETDATE() where ID="+lblId.Text+";");

            }
            if (grView2.Rows.Count > 0)
            {
                sb.Append("update lp_Configuration_main set total=" + total + " where userID=" + _Utility.GetInfoBySession().m_sUserID + " and DATEDIFF(DD,workDay,GETDATE())=0 and isComplete=0");

                ZLDC.Topo.BLL.Estate.lp_Basis.lp_Configuration_main_add(sb.ToString());///插入量化项
            }

        }
    }
}
